package com.bird.generate.ddd.application

import com.bird.generate.ddd.application.pl.AddAggregateRootRequest
import com.bird.generate.ddd.application.pl.AddEntityRequest
import com.bird.generate.ddd.application.pl.AddValueObjectRequest
import com.bird.generate.ddd.domain.AggregateRootEntity
import com.bird.generate.ddd.domain.EntityEntity
import com.bird.generate.ddd.domain.ValueObjectEntity

fun AddAggregateRootRequest.toAggregateRoot(): AggregateRootEntity {
    return AggregateRootEntity(
        name = this.name,
        description = this.description,
        enName = this.enName,
        version = this.version,
        moduleName = this.moduleName,
        projectName = this.projectName,
        valueObjects = this.valueObjects.map { it.toValueObject() },
        entities = this.entities.map { it.toEntity() },
        creator = this.creator,
        multiTenant = this.multiTenant,
        comPrefix = this.comPrefix,
        fields = this.fields
    )
}

fun AddEntityRequest.toEntity(): EntityEntity {
    return EntityEntity(
        enName = this.enName,
        name = this.name,
        description = this.description,
        fields = this.fields
    )
}

fun AddValueObjectRequest.toValueObject(): ValueObjectEntity {
    return ValueObjectEntity(
        enName = this.enName,
        name = this.name,
        description = this.description,
        fields = this.fields,
        isEnum = this.isEnum
    )
}